using Holoville.HOTween;
using UnityEngine;

[RequireComponent(typeof(BoxCollider))]
public class ZipLine : MonoBehaviour
{
	public Transform endPoint;

	public float durationInSeconds = 2f;

	public AnimationCurve curve;

	private void Start()
	{
		HOTween.Init();
		GetComponent<BoxCollider>().isTrigger = true;
	}

	private void OnTriggerEnter(Collider other)
	{
		if (other.tag.Equals("Player") && other.gameObject == GameController.instance.myPlayer && endPoint != null && !GameController.instance.useZipLine)
		{
			GameController.instance.playerScript.tController.gravity = 0f;
			GameController.instance.playerScript.tController.joyScript.gameObject.SetActive(false);
			GameController.instance.playerScript.tController.joyScript.position = Vector2.zero;
			GameController.instance.useZipLine = true;
			GameController.instance.playerScript.tController.moveSpeed = 0f;
			HOTween.To(GameController.instance.playerScript.transform, 0.3f, new TweenParms().Prop("position", base.transform.position).OnComplete(StartMoving));
		}
	}

	public void StartMoving()
	{
		HOTween.To(GameController.instance.playerScript.transform, durationInSeconds, new TweenParms().Prop("position", endPoint.position).OnComplete(RemoveFromZipLine)).easeAnimationCurve = curve;
	}

	public void RemoveFromZipLine()
	{
		GameController.instance.useZipLine = false;
		GameController.instance.playerScript.alreadyDontFly();
		GameController.instance.playerScript.tController.ResetFlyDown();
		GameController.instance.playerScript.tController.gravity = 20f;
		GameController.instance.playerScript.tController.joyScript.gameObject.SetActive(true);
	}
}
